package what.basic.swingcommon;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.*;

import what.basic.basiccomponent.*;
public class swingkeyaccess {

	ImageIcon ico1=new ImageIcon("e:/1.jpg","picture1");
	ImageIcon ico2=new ImageIcon("e:/1.jpg","picture1");
	ImageIcon ico3=new ImageIcon("e:/1.jpg","picture1");
	ImageIcon ico4=new ImageIcon("e:/1.jpg","picture1");
	ImageIcon ico5=new ImageIcon("e:/1.jpg","picture1");
	JLabel lbl1=new JLabel(ico1);
	JLabel lbl2=new JLabel(ico2);
	JLabel lbl3=new JLabel(ico3);
	JLabel lbl4=new JLabel(ico4);
	JLabel lbl5=new JLabel(ico5);
	static JButton b1=new JButton("bt1");
	JFrame f=new Jframe().jframe("border test", 400, 300, true);
	static JButton b2=new JButton("dss");
	static JButton b3=new JButton("bbccc");
	 public void icon1(){
	//	JFrame f=new Jframe().jframe("border test", 400, 300, true);
		JPanel jp=new JPanel();
		f.setContentPane(jp);
		RedLineBorder border=new RedLineBorder();
		buttonAction ba=new buttonAction("actiontest");
		b1.setAction(ba);
		
		menuAction ma=new menuAction("exit");
		b2.setAction(ma);
		jp.setBorder(border);
		jp.add(lbl1);
		jp.add(lbl2);
		jp.add(lbl3);
		jp.add(lbl4);
		jp.add(lbl5);
		jp.add(b1);
		jp.add(b2);
		jp.add(b3);
		b1.getInputMap(2).put(KeyStroke.getKeyStroke('B'), "open");
		b1.getActionMap().put("open",ba);
		b2.getInputMap(2).put(KeyStroke.getKeyStroke('S',java.awt.Event.CTRL_MASK,true),"Exit");
		b2.getActionMap().put("Exit", ma);
		b1.setFocusable(true);
		f.pack();
		framefocus00 fo1=new framefocus00();
		f.setFocusTraversalPolicy(fo1);
		
		f.addWindowListener(new WindowAdapter(){
			public void windowActivated(WindowEvent e){
				b2.requestFocusInWindow();
			}
		});
	}
	public static void main(String[] args) {
		new swingkeyaccess().icon1();

	}
class buttonAction extends AbstractAction{
	public buttonAction(String text){
		super(text);
	}
	public void actionPerformed(ActionEvent arg0) {
		//
		if(arg0.getSource()==(Object)b1)
			lbl2.setText("xdddss");
		}
}	
class menuAction extends AbstractAction{
	public menuAction (String text){
		super(text);
	}
	public void actionPerformed(ActionEvent arg0) {
		int i=JOptionPane.showConfirmDialog(null,"exit ?","exit",JOptionPane.YES_NO_CANCEL_OPTION);
		System.out.println(i);
		if(i==0)
			f.dispose();
	}
}
class accessible implements Accessible{
	public AccessibleContext getAccessibleContext() {
		
		return null;
	}
	
}
}

class framefocus00 extends FocusTraversalPolicy{
	public Component getComponentAfter(Container arg0, Component arg1) {
		if(arg1.equals(swingkeyaccess.b1))
			return swingkeyaccess.b2;
		else if(arg1.equals(swingkeyaccess.b2))
			return swingkeyaccess.b3;
		else if(arg1.equals(swingkeyaccess.b3))
			return swingkeyaccess.b1;
		return swingkeyaccess.b1;
	}

	@Override
	public Component getComponentBefore(Container arg0, Component arg1) {
		if(arg1.equals(swingkeyaccess.b1))
			return swingkeyaccess.b3;
		else if(arg1.equals(swingkeyaccess.b2))
			return swingkeyaccess.b1;
		else if(arg1.equals(swingkeyaccess.b3))
			return swingkeyaccess.b2;
		return swingkeyaccess.b1;
	}

	@Override
	public Component getDefaultComponent(Container arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Component getFirstComponent(Container arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Component getLastComponent(Container arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
